﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess.IService;
using System.Data;
using Utility;
using System.Collections;
using System.Data.SqlClient;
using Entity;

namespace DataAccess.Service
{
    public class AccommodationService : IAccommodationService
    {
        public DataTable selectDormitoryNum(String dormitoryAddress, String buildNum)
        {

            string commandText = "select * from Dormitory,Apartment where  Dormitory.apaId=Apartment.apaId and Address='" + dormitoryAddress + "'and apaName='" + buildNum + "'";
            string[] colNames = new string[]
               {
                "dorNum",
                "dorId"
               };
            return SQLHelper.generateDataTable(commandText, colNames);

          
           
        }

        public Dormitory selectDormitoryInfor(String dormitoryId)
        {
            Dormitory dormitory = new Dormitory();
            string commandText = string.Format("select * from Dormitory where dorId=@dormitoryId");
            SqlParameter[] paras = new SqlParameter[]
            {
               new SqlParameter("dormitoryId", dormitoryId)
            };
            SqlDataReader sdReader = SQLHelper.ExecuteReader(commandText, paras);
            if (sdReader.Read())
            {
                dormitory.Address = Convert.ToString(sdReader["address"]);
                dormitory.DormitoryNum = Convert.ToString(sdReader["dorNum"]);
                dormitory.StudentNum = Convert.ToInt32(sdReader["totalNum"]);
            }
            return dormitory;
        }



        public String selectDormitoryId(string stuId)
        {
            String dormitoryId = "";
            string commandText = string.Format("select dorId from StudentAccommodation  where stuId=@stuId");
            SqlParameter[] paras = new SqlParameter[]
            {
              new SqlParameter("@stuId", stuId)
            };
            SqlDataReader sdReader = SQLHelper.ExecuteReader(commandText, paras);
            if (sdReader.Read())
            {
                dormitoryId = sdReader["dorId"].ToString();//Convert.ToInt32(sdReader["dorId"]);
            }
            return dormitoryId;
        }

    }
}
